/**
 * 5.2自定义对象
 */
//5.2.1对象定义&&5.2.2访问对象成员&&5.2.3对象成员便利
console.log("5.2.1对象定义&&5.2.2访问对象成员&&5.2.3对象成员便利")
var o1 = {
    name: "会飞的猪",//成员属性01.name
    age: 20,//成员属性01.age
    say: function () {//成员方法01.say
        return "姓名" + this.name + " 年龄" + this.age;
    }
};
o1.gender = "男";//为对象增加属性
for (var i in o1) {//对象成员便利
    console.log(o1[i])
}
o1["name"] = "会飞的猫";
console.log(o1["name"]);//相当于o1["id"]=会飞的猫或o1.name="会飞的猫"

//【例5-1】
var k = document.getElementById("k");
var v = document.getElementById("v");
var btn = document.getElementById("btn");
var o = {};
btn.onclick = function () {
    o[k.value] = v.value;
    console.log("例5-1")
    console.log(o);//
};

//多学一招
console.log("多学一招");
var obj = {name: "Tom", age: 16};
console.log("name" in obj);
console.log("gender" in obj);

//5.2.4 深拷贝与浅拷贝
//浅拷贝 对象，数组
console.log("5.2.4深拷贝与浅拷贝  浅拷贝")
var p1={name:"Slsher",age:20};
var p2=p1;
p2.name="Tom";
console.log(p1);
console.log(p2);
console.log(p1===p2);

//深拷贝 数值，字符型
console.log("5.2.4深拷贝与浅拷贝 深拷贝")
var p3="slsher";
var p4=p3;
var p4="Tom";
console.log(p3);
console.log(p4);
console.log(p4==p3);

